import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

//import GridPanel.ActionType;

public class Form extends JFrame {
	int gridStep = 15;

	JMenuBar menuBar;
	JToolBar toolBar;
	JTabbedPane tabbedPane;
	JTextField textField;
	GridPanel help;

	public Form() {
		super("Program");
		this.setTitle("Program");
		setDefaultCloseOperation(EXIT_ON_CLOSE);

		SetMenuBar();

		SetToolBar();

		SetTabbedPane();

		SetTable();

		this.setSize(800, 600);
	}

	private void SetMenuBar() {
		menuBar = new JMenuBar();
		JMenu file = new JMenu("File");
		JMenu opt = new JMenu("Options");
		JMenu exit = new JMenu("Exit");

		exit.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent event) {
				System.exit(0);
			}
		});

		menuBar.add(file);
		menuBar.add(opt);
		menuBar.add(exit);
		setJMenuBar(menuBar);
	}

	private void SetToolBar() {

		toolBar = new JToolBar("Instrumental Panel");
		getContentPane().add(toolBar, BorderLayout.NORTH);

		JButton selectHand = new JButton("Hand");
		JButton createStartNode = new JButton("Start");
		JButton createFinishNode = new JButton("Finish");
		JButton createActivity = new JButton("Activity");
		JButton createRhomb = new JButton("Rhomb");
		JButton createArrow = new JButton("Arrow");
		JButton setGrid = new JButton("OK");

		selectHand.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent event) {
				// drawAct = false;
				// drawRhomb = false;
				help.setAction(GridPanel.ActionType.NONE);
			}
		});

		createActivity.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent event) {
				// drawAct = true;
				// drawRhomb = false;
				help.setAction(GridPanel.ActionType.DRAW_ACTIVITY);
			}
		});

		createRhomb.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent event) {
				// drawAct = false;
				// drawRhomb = true;
				help.setAction(GridPanel.ActionType.DRAW_DECISION);
			}
		});

		setGrid.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent event) {
				int step = Integer.parseInt(textField.getText());
				if (step != 0) {
					help.setGridStep(step);
					repaint();
				}
			}
		});

		createArrow.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent event) {
				help.setAction(GridPanel.ActionType.DRAW_ARROW);
			}
		});

		createStartNode.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent event) {

				help.setAction(GridPanel.ActionType.DRAW_START_NODE);
			}
		});

		createFinishNode.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent event) {

				help.setAction(GridPanel.ActionType.DRAW_FINISH_NODE);
			}
		});

		toolBar.add(selectHand);
		toolBar.addSeparator();
		toolBar.add(createStartNode);
		toolBar.add(createFinishNode);
		toolBar.add(createActivity);
		toolBar.add(createRhomb);
		toolBar.add(createArrow);
		toolBar.addSeparator();

	}

	private void SetTabbedPane() {
		tabbedPane = new JTabbedPane(JTabbedPane.TOP,
				JTabbedPane.WRAP_TAB_LAYOUT);
		help = new GridPanel();

		getContentPane().add(help);

		help.addContainerListener(new ContainerAdapter() {

			public void componentAdded(ContainerEvent e) {
				try {
					((Element) e.getChild()).borderExitFix();
				} catch (ClassCastException ex) {

				}
			}

		});
	}

	void SetTable() {
		PropTable pt = new PropTable(this);
	}

	public void paintComponent(Graphics g) {

	}
}
